﻿namespace Xioa_UI.Service;

public static class FuncCatch
{
    public static T? CatchError<T>(this Func<T> func, Action<Exception>? action = null)
    {
        try
        {
            return func();
        }
        catch (Exception e)
        {
            action?.Invoke(e);
        }

        return default;
    }
    
    public static void CatchError(this Action func, Action<Exception>? action = null)
    {
        try
        {
             func();
        }
        catch (Exception e)
        {
            action?.Invoke(e);
        }
    }
}
